/*
 * 流程配置 api 公共模块
 */
import { gatewayRequest, request } from '@ydc/workbench-tools';

const Url = {
  masterDataApi: 'metadata/invokeApiV2.json', // 主数据
  getSelectedAllSalaryItemConfig: 'biz/hr/salary/config/salaryItemConfig/getSelectedAllSalaryItemConfig.json',
  getSelectedSalaryItemConfig: 'biz/hr/salary/config/salaryItemConfig/getSelectedSalaryItemConfig.json',
  getEmployeeChiefList: 'biz/hr/core_hr/employee/getEmployeeChiefList.json',
  advanceSearch: 'search/advanceSearch.json',
  query: 'biz/hr/core_hr/address/queryProvinceCityAddressTree.json',
};

// 获取省市区详情
export const getQueryGB2260 = (): Promise<{ data: any }> => {
  return gatewayRequest(Url.query, {}).then((d) => d);
};

// 根据流程实例id获取审批列表信息
export function getTaskDetailForProcessShow(params: any) {
  const param = {
    request: {
      name: 'taskDetailForProcessShow',
      ...params,
    },
  };
  return gatewayRequest('bpmn/query/historic-task-instances/process-instance/taskDetailProcessShow.json', { param });
}

// 根据业务流程code获取流程配置信息 todo
export function getProcessInfoByCode(app: any, params: any) {
  const param = {
    request: {
      appId: app.appId,
      version: app.version,
      name: 'getProcessInfoByCode',
      params,
    },
  };
  return gatewayRequest(Url.masterDataApi, { param });
}

// 创建或更新流程配置信息 todo
export function createORUpdateOfficialYdcCoreHrProcessMap(app: any, params: any) {
  const param = {
    request: {
      appId: app.appId,
      version: app.version,
      name: 'CreateORUpdateOfficialYdcCoreHrProcessMap',
      params,
    },
  };
  return gatewayRequest(Url.masterDataApi, { param });
}

// 根据流程信息id删除流程配置信息
export function deleteOfficialYdcCoreHrProcessMap(app: any, params: any) {
  const param = {
    request: {
      appId: app.appId,
      version: app.version,
      name: 'DeleteOfficialYdcCoreHrProcessMap',
      params,
    },
  };
  return gatewayRequest(Url.masterDataApi, { param });
}

// 证件类型
export function getCardType() {
  const param = {
    request: {
      dictName: '证件类型',
    },
  };
  return gatewayRequest('metadata/listDictItems.json', { param });
}

//学历

export function getEducation() {
  const param = {
    request: {
      dictName: '学历',
    },
  };
  return gatewayRequest('metadata/listDictItems.json', { param });
}

// 获取其他应用appid
export function getAppId(data: any) {
  const param = data;
  return gatewayRequest('metadata/queryListOfficialAppByCodes.json', { param });
}

// 获取薪资系统配置项
export function getSalaryItem(appId: string) {
  const param = {
    request: {
      name: 'ListOfficialSwbSalaryItemConfigRecords',
      version: '__sys_draft_version__',
      appId,
    },
  };
  return gatewayRequest(Url.masterDataApi, { param });
}

// 查询系统配置
export function querySystemConfig(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/salary/config/systemConfig/querySystemConfig.json', {
    param,
  });
}

// 核心人事配置
export function saveSystemConfig(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/config/systemConfig/saveSystemConfig.json', {
    param,
  });
}

// 查询核心人事配置
export function queryHrSystemConfig(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/config/systemConfig/querySystemConfig.json', {
    param,
  });
}
// 查询员工负责的部门
export function queryManagedDept(params: any) {
  const param = {
    request: params,
  };
  return gatewayRequest('usercenter/department/queryManagedDept.json', {
    param,
  });
}

// 获取e签宝盖章跳转链接
export function getManualStampingURL(app: any, params: any) {
  const param = {
    ...app,
    ...params,
  };
  return gatewayRequest('biz/hr/core_hr/contract/getManualStampingURL.json', {
    param,
  });
}

// 催办
export function resendMessage(params: any) {
  const param = {
    request: params,
  };
  return gatewayRequest('bpmn/runtime/tasks/resendMessage.json', { param });
}

// 获取页面自定义字段
export function getMetadataInfoByPage(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/hmcMetaService/getMetadataInfoByPage.json', {
    param,
  });
}

//获取员工基本信息（包括已离职的）
export function getAnyChiefByIdentityId(identityId: any) {
  const param = {
    request: {
      identityId: identityId,
    },
  };
  return gatewayRequest('usercenter/hrEmployeeService/getAnyChiefByIdentityId.json', {
    param,
  });
}

// 催办
export function urgeProcess(params: any) {
  const param = {
    request: params,
  };
  return gatewayRequest('bpmn/runtime/tasks/urgeProcess.json', { param });
}

export function getEmployeeAllDetail(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/employee/queryUserDefineInfoByIdentityId.json', {
    param,
  });
}

// 完善个人档案信息
export function improveEmployeeBaseInfo(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/employee/improveEmployeeBaseInfo.json', {
    param,
  });
}

// 工号配置
export function saveWork(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/work_no/config/save.json', {
    param,
  });
}

// 获取下N个可用工号
export function getWorkNo(app: any) {
  const param = {
    ...app,
    request: {
      limit: 1,
    },
  };
  return gatewayRequest('biz/hr/core_hr/work_no/next.json', {
    param,
  });
}

// 获取公司地址
export function getCompanyAddrById(params: any) {
  const param = {
    req: params,
  };
  return gatewayRequest('usercenter/companyService/getCompanyById.json', {
    param,
  });
}

// 根据离职id获取离职信息
export function getContractTemplateVariableByResignId(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/resign/getContractTemplateVariableByResignId.json', {
    param,
  });
}

// 根据identiyId获取离职信息
export function getContractTemplateVariableByIdentityId(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/resign/getContractTemplateVariableByIdentityId.json', {
    param,
  });
}

// 获取页面自定义导出字段
export function getExcelMetadataInfoByPage(app: any, params: any) {
  const param = {
    ...app,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/hmcMetaService/getExcelMetadataInfoByPage.json', {
    param,
  });
}

// 字典接口
export function getDictionary(dictName: string) {
  const param = {
    request: {
      dictName,
    },
  };
  return gatewayRequest('metadata/listDictItems.json', { param });
}

export function queryGraphVersionList(url: string, data: any) {
  const param = {
    method: 'get',
    params: {
      ...data,
    },
  };
  return request(url, param);
}

export function getEmployeeChiefList(app: any, params: any) {
  const param = {
    appId: app.appId,
    version: app.version,
    name: params,
  };

  return gatewayRequest(Url.getEmployeeChiefList, { param });
}

export function advanceSearch(keyword: any) {
  const param = {
    request: {
      indexName: 'sys_hr_employee',
      text: keyword,
      fieldNames: ['userName', 'userName.pinyin', 'nickName', 'nickName.pinyin'],
    },
  };

  return gatewayRequest(Url.advanceSearch, { param });
}
// 返回当前选中的薪资项
export function getSelectedSalaryItemConfig(app: any) {
  const param = {
    appId: app.appId,
    version: app.version,
  };
  return gatewayRequest(Url.getSelectedSalaryItemConfig, { param });
}

// 保存合同续签配置
export function saveRenewContractConfig(app: any, params: any) {
  const param = {
    appId: app.appId,
    version: app.version,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/resign/saveRenewContractConfig.json', {
    param,
  });
}

// 保存合同预警通知配置
export function saveContractNoticeConfig(app: any, params: any) {
  const param = {
    appId: app.appId,
    version: app.version,
    request: params,
  };
  return gatewayRequest('biz/hr/core_hr/resign/saveContractNoticeConfig.json', {
    param,
  });
}

// 返回当前选中的薪资项
export function getSelectedAllSalaryItemConfig(app: any) {
  const param = {
    appId: app.appId,
    version: app.version,
  };
  return gatewayRequest(Url.getSelectedAllSalaryItemConfig, { param });
}
